package com.janson.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.janson.entity.Job;
import com.janson.entity.JobCategory;
import com.janson.service.impl.JobCategoryServiceImpl;
import com.janson.service.impl.JobServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author janson
 * @since 2022-03-30
 */
@Controller
public class JobCategoryController {

    @Autowired
    JobServiceImpl jobService;
    @Autowired
    JobCategoryServiceImpl jobCategoryService;

    @GetMapping("/job/category/{id}/{page}/{limit}")
    public String jobPage(@PathVariable int id,@PathVariable int page,
                          @PathVariable int limit,Model model){
        Page<Job> pageParam = new Page<>(page,limit);
        jobService.page(pageParam,new QueryWrapper<Job>()
                        .eq("category_id",id)
                        .orderByDesc("gmt_create"));
        List<Job> records = pageParam.getRecords();
        model.addAttribute("blogList",records);
        model.addAttribute("pageParam",pageParam);

        //查询分类的信息
        JobCategory category = jobCategoryService.getById(id);
        model.addAttribute("thisCategoryName",category.getCategory());

        //全部分类
        List<JobCategory> jobCategoryList = jobCategoryService.list(null);
        model.addAttribute("categoryList",jobCategoryList);

        return "blog/list";
    }


}

